package com.blog.common.result;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class R<T> {
    private Integer code;
    private String msg;
    private T data;

    public static <T> R success() {
       return R.<T>builder().code(ResponseEnum.SUCCESS.getCode()).msg(ResponseEnum.SUCCESS.getMsg()).build();
    }

    // 成功
    public static <T> R<T> success(T data) {
        return R.<T>builder().code(ResponseEnum.SUCCESS.getCode()).msg(ResponseEnum.SUCCESS.getMsg()).data(data).build();
    }

    public static <T> R<T> success(T data, String msg) {
        return R.<T>builder().code(ResponseEnum.SUCCESS.getCode()).msg(msg).data(data).build();
    }


    public static <T> R<T> error(ResponseEnum responseEnum) {
        return R.<T>builder().code(responseEnum.getCode()).msg(responseEnum.getMsg()).build();
    }

    public static <T> R<T> error(String msg) {
        return R.<T>builder().code(ResponseEnum.ERROR.getCode()).msg( msg).build();
    }




}
